package hos.demo

import androidx.lifecycle.ViewModel
import hos.thread.lifecycle.getLifecycleJob
import hos.thread.lifecycle.getLifecycleJobLive

/**
 * <p>Title: MainViewModel </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @date : 2023/8/2 9:41
 * @version : 1.0
 */
class MainViewModel : ViewModel() {

    val progress by lazy {
        getLifecycleJob {
            for (i in 0 until 100) {
                if (isCancel()) {
                    return@getLifecycleJob "取消"
                }
                Thread.sleep(400)
                progressUpdate(i.toDouble())
            }
            "测试线程进度"
        }

    }

    val progressLive by lazy {
        getLifecycleJobLive {
            for (i in 0 until 100) {
                if (isCancel()) {
                    return@getLifecycleJobLive "取消"
                }
                Thread.sleep(200)
                progressUpdate(i.toDouble())
            }
            "测试线程进度"
        }
    }
}